package com.gaff.emp.core.config;

import com.gaff.emp.core.sftp.SftpClient;
import com.gaff.emp.core.sftp.SftpProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@ConditionalOnProperty(prefix = "sftp", name = "enable", havingValue = "true")
public class SftpConfig {

    @Value("${sftp.host}")
    private String host;

    @Value("${sftp.port:22}")
    private int port;

    @Value("${sftp.username}")
    private String username;

    @Value("${sftp.password}")
    private String password;

    @Value("${sftp.home-dir}")
    private String homeDir;

    @Value("${sftp.connect-timeout:15000}")
    private int connectTimeout;

    @Value("${sftp.connected-timeout:15000}")
    private int connectedTimeout;


    @Bean
    public SftpClient sftpClient() {
        SftpProperties properties = new SftpProperties();
        properties.setHost(host);
        properties.setPort(port);
        properties.setUsername(username);
        properties.setPassword(password);
        properties.setHomeDir(homeDir);
        properties.setConnectTimeout(connectTimeout);
        properties.setConnectedTimeout(connectedTimeout);
        return new SftpClient(properties);
    }

}
